<template>
  <div v-if="hasAdmin" class="searchData">
    <div class="left">
      <h4>我的模板</h4>
      <div class="model-group">
        <div class="model-item" @click="handleClickSearchModel(item.content)" v-for="(item, index) in modelList"
          :key="index">
          <el-button @click.prevent.stop="handleDeleteSearchModel(item.id)" class="model-close" size="small"
            type="primary" icon="CloseBold" circle />

          <h5>{{ item.name }}</h5>
          <div class="model-introduce">简介：{{ item.introduce }}</div>
          <div class="model-time">
            创建时间：{{ dayjs(item.createTime).format('YYYY-MM-DD') }}
          </div>
        </div>
      </div>
    </div>
    <div class="right">
      <el-form :model="queryParams" ref="queryRef" :inline="true">
        <div class="mb10">
          <el-form-item label="数据限制" prop="limitCnt">
            <el-input-number v-model="queryParams.limitCnt" :min="1" :max="2147483647" controls-position="right"
              size="small" />
          </el-form-item>

          <el-form-item label="批次" prop="batchNameList">
            <InvertSelection v-model="queryParams.batchNameList" :data="optionList" key-field="id"
              label-field="batchName" value-field="batchName" placeholder="请选择批次" />
          </el-form-item>

          <el-form-item label="周期" style="width: 270px">
            <el-date-picker v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
              start-placeholder="开始日期" end-placeholder="结束日期" @change="handleDateValue" size="small" />
          </el-form-item>

          <el-form-item label="企业名称" prop="companyName">
            <el-input size="small" v-model.trim="queryParams.companyName" placeholder="请输入企业名称" />
          </el-form-item>

          <el-form-item label="手机号" prop="phoneNum">
            <el-input size="small" v-model.trim="queryParams.phoneNum" placeholder="请输入手机号" />
          </el-form-item>

          <el-form-item label="省" prop="provinceList">
            <InvertSelection style="width: 100px" v-model="queryParams.provinceList" :data="provinces" key-field="name"
              label-field="name" value-field="name" placeholder="请选择省" />
          </el-form-item>

          <!-- <el-form-item label="风险等级" prop="riskLevel">
            <el-select
              size="small"
              v-model="queryParams.riskLevel"
              placeholder="请选择风险等级"
              style="width: 120px"
              clearable
            >
              <el-option
                v-for="item in riskLevelList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item> -->
          <el-form-item label="要素一致性" prop="checkMobile">
            <el-select size="small" v-model="queryParams.checkMobile" placeholder="请选择" style="width: 80px" clearable>
              <el-option v-for="item in checkMobileOption" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="一致性" prop="consistence">
            <el-select size="small" v-model="queryParams.consistence" placeholder="请选择" style="width: 80px" clearable>
              <el-option v-for="item in consistenceOption" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="类型" prop="postNameList">
            <el-select style="width: 100px" size="small" v-model="queryParams.postNameList" placeholder="类型" multiple
              clearable>
              <el-option v-for="item in postNameOption" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>

          <el-form-item label="在营状态" prop="entstatusName">
            <el-select size="small" style="width: 100px" v-model="queryParams.entstatusName" placeholder="在营状态"
              clearable>
              <el-option v-for="item in entstatusNameOption" :key="item.value" :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>

          <el-form-item label="年限">
            <el-select size="small" v-model="queryParams.yearType" clearable style="width: 100px">
              <el-option v-for="(item, index) in yearTypes" :key="index" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>

          <el-form-item label="点呼导出次数" prop="exportCntSingleMin">
            <el-form-item prop="exportCntSingleMin">
              <el-input size="small" v-model="queryParams.exportCntSingleMin" placeholder="请输入" style="width: 60px" />
            </el-form-item>

            <span style="margin: 0 10px">~</span>
            <el-form-item prop="exportCntSingleMax">
              <el-input size="small" v-model="queryParams.exportCntSingleMax" placeholder="请输入" style="width: 60px" />
            </el-form-item>
          </el-form-item>

          <el-form-item label="群呼导出次数">
            <el-form-item prop="exportCntBatchMin">
              <el-input size="small" controls-position="right" v-model="queryParams.exportCntBatchMin" placeholder="请输入"
                style="width: 60px" />
            </el-form-item>

            <span style="margin: 0 10px">~</span>

            <el-form-item prop="exportCntBatchMax">
              <el-input size="small" controls-position="right" v-model="queryParams.exportCntBatchMax" placeholder="请输入"
                style="width: 60px" />
            </el-form-item>
          </el-form-item>

          <el-form-item label="AI导出次数">
            <el-form-item prop="exportCntAiMin">
              <el-input size="small" v-model="queryParams.exportCntAiMin" placeholder="请输入" style="width: 60px" />
            </el-form-item>

            <span style="margin: 0 10px">~</span>
            <el-form-item prop="exportCntAiMax">
              <el-input size="small" v-model="queryParams.exportCntAiMax" placeholder="请输入" style="width: 60px" />
            </el-form-item>
          </el-form-item>

          <el-form-item label="企业类型" prop="capTypeNameList">
            <InvertSelection style="width: 100px" v-model="queryParams.capTypeNameList" :data="capTypeList"
              key-field="id" label-field="name" value-field="name" placeholder="企业类型" />
          </el-form-item>
          <el-form-item label="过滤企业" prop="filterateCompany">
            <el-switch v-model="queryParams.filterateCompany" inline-prompt active-text="是" active-value="1"
              inactive-text="否" inactive-value="0" />
          </el-form-item>
          <el-form-item label="纳税开票同步状态" prop="nsStatus">
            <el-select style="width: 100px" v-model="queryParams.nsStatus" placeholder="请选择" size="small" clearable>
              <el-option label="未同步" :value="-1" />
              <el-option label="已同步" :value="1" />
              <el-option label="已同步但无数据" :value="2" />
            </el-select>
          </el-form-item>
          <el-form-item label="纳税额度(万元)" prop="nsInfo">
            <el-select style="width: 100px" v-model="queryParams.nsInfo" placeholder="请选择" size="small" clearable
              multiple>
              <el-option label="5" :value="5" />
              <el-option label="2" :value="2" />
              <el-option label="0" :value="0" />
            </el-select>
          </el-form-item>
          <el-form-item label="开票额度(万元)" prop="kpInfo">
            <el-select style="width: 100px" v-model="queryParams.kpInfo" placeholder="请选择" size="small" clearable
              multiple>
              <el-option label="500" :value="500" />
              <el-option label="100" :value="100" />
              <el-option label="0" :value="0" />
            </el-select>
            <!-- <el-input
              size="small"
              v-model="queryParams.kpInfo"
              placeholder="请输入"
            /> -->
          </el-form-item>
          <el-form-item label="风险总计情况" prop="allHis">
            <el-select v-model="queryParams.allHis" size="small" clearable style="width: 100px">
              <el-option :value="0" label="否"></el-option>
              <el-option :value="-1" label="未知"></el-option>
              <el-option :value="1" label="是"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否有标签" prop="haveTag">
            <el-select clearable v-model="queryParams.haveTag" class="wh" placeholder="请选择" size="small"
              style="width: 100px">
              <el-option v-for="item in whetherOrNotOptions" :key="item.value" :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <!-- <el-form-item label="是否有自身风险" prop="ownHis">
            <el-select
              v-model="queryParams.ownHis"
              size="small"
              clearable
              style="width: 100px"
            >
              <el-option :value="0" label="否"></el-option>
              <el-option :value="-1" label="未知"></el-option>
              <el-option :value="1" label="是"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否有关联风险" prop="corHis">
            <el-select
              v-model="queryParams.corHis"
              size="small"
              clearable
              style="width: 100px"
            >
              <el-option :value="0" label="否"></el-option>
              <el-option :value="-1" label="未知"></el-option>
              <el-option :value="1" label="是"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否有其他风险" prop="otherHis">
            <el-select
              v-model="queryParams.otherHis"
              size="small"
              clearable
              style="width: 100px"
            >
              <el-option :value="0" label="否"></el-option>
              <el-option :value="-1" label="未知"></el-option>
              <el-option :value="1" label="是"></el-option>
            </el-select>
          </el-form-item> -->
          <el-form-item>
            <el-button type="primary" size="small" icon="Filter" @click="handleChooseSearch">
              筛选
            </el-button>
            <el-button type="primary" size="small" icon="Filter" @click="handleTagSearch">
              标签筛选
            </el-button>
            <el-button type="primary" size="small" icon="Search" @click="handleQuery(queryRef)">
              搜索
            </el-button>
            <el-button icon="Refresh" size="small" @click="resetQuery">
              重置
            </el-button>
            <el-button icon="Star" size="small" @click="saveModelDialogChange(true)">
              设置为模板
            </el-button>
          </el-form-item>
        </div>

        <div class="headRight">
          <el-form-item>
            <el-button type="success" icon="Document" size="small" @click="handleDataSummary">
              数据汇总
            </el-button>
            <el-button v-hasPermi="['fileContent:searchData:export']" type="primary" size="small" icon="Download"
              @click="handleExport(data, false)">
              导出
            </el-button>
            <el-button v-hasPermi="['fileContent:searchData:delete']" type="warning" icon="Delete" size="small"
              @click="handleDelete('all')">
              按选中删除
            </el-button>
            <el-button v-hasPermi="['fileContent:searchDataBatch:delete']" type="danger" icon="Delete" size="small"
              @click="handleDeleteByParams">
              按条件删除
            </el-button>
            <el-button link size="small" @click="handleColumnsShow">
              <el-icon size="16">
                <Setting />
              </el-icon>
            </el-button>
          </el-form-item>
        </div>
      </el-form>
      <el-table v-loading="loading" ref="multipleTableRef" :data="tableList" @selection-change="handleSelectionChange"
        :row-key="(row) => row.id" height="440" style="margin-top: 10px">
        <el-table-column type="selection" :reserve-selection="true" width="55" fixed="left" />
        <el-table-column label="企业名称" prop="companyName" fixed="left" width="260" :show-overflow-tooltip="true"
          v-if="handleShow('企业名称', chooseList)" />

        <el-table-column label="手机号" prop="phoneNum" width="140" v-if="handleShow('手机号', chooseList)" />

        <!-- <el-table-column
          v-if="handleShow('风险等级', chooseList)"
          label="风险等级"
          prop="riskLevel"
          :formatter="
            (row) =>
              row.riskLevel === '0'
                ? '安全'
                : row.riskLevel === '1'
                ? '风险'
                : '未知'
          "
        /> -->

        <el-table-column label="导入法人" prop="legalPerson" v-if="handleShow('导入法人', chooseList)" />

        <el-table-column label="校对法人" prop="checkLegal" v-if="handleShow('校对法人', chooseList)" />

        <el-table-column v-if="handleShow('一致性', chooseList)" label="一致性" :formatter="(row) =>
          row.consistence === 1 ? '是' : row.consistence === 2 ? '否' : '/'
          " />

        <el-table-column label="类型" prop="postName" v-if="handleShow('类型', chooseList)" />

        <el-table-column label="省" prop="province" v-if="handleShow('省', chooseList)" />

        <el-table-column label="市" prop="city" v-if="handleShow('市', chooseList)" />

        <el-table-column label="区" prop="area" v-if="handleShow('区', chooseList)" />

        <el-table-column label="在营状态" prop="entstatusName" width="160" v-if="handleShow('在营状态', chooseList)" />
        <el-table-column label="要素一致性" prop="checkMobile" :formatter="(row) =>
          row.checkMobile == -1
            ? '未知'
            : row.checkMobile == 0
              ? '一致'
              : '不一致'
          " width="160" v-if="handleShow('要素一致性', chooseList)" />

        <el-table-column label="注册时间" prop="esdate" width="160" v-if="handleShow('注册时间', chooseList)" />

        <el-table-column label="注册资金(万)" prop="regCap" width="150" v-if="handleShow('注册资金(万)', chooseList)" />

        <el-table-column label="实缴资金(万)" prop="paidCap" width="150" v-if="handleShow('实缴资金(万)', chooseList)" />

        <el-table-column label="一级行业" prop="industryphy" width="160" :show-overflow-tooltip="true"
          v-if="handleShow('一级行业', chooseList)" />

        <el-table-column label="二级行业" prop="industryphy1" width="160" :show-overflow-tooltip="true"
          v-if="handleShow('二级行业', chooseList)" />

        <el-table-column label="三级行业" prop="industryphy2" width="160" :show-overflow-tooltip="true"
          v-if="handleShow('三级行业', chooseList)" />

        <el-table-column label="四级行业" prop="enttypeName" width="160" :show-overflow-tooltip="true"
          v-if="handleShow('四级行业', chooseList)">
          <template #default="scope">
            <span>{{ scope.row.enttypeName }}</span>
          </template>
        </el-table-column>

        <el-table-column label="信用代码" prop="creditCode" width="180" :show-overflow-tooltip="true"
          v-if="handleShow('信用代码', chooseList)" />

        <el-table-column label="批次" prop="batchName" width="180" :show-overflow-tooltip="true"
          v-if="handleShow('批次', chooseList)" />

        <el-table-column label="创建时间" prop="createTime" width="160" v-if="handleShow('创建时间', chooseList)" />

        <el-table-column label="更新时间" prop="updateTime" width="160" v-if="handleShow('更新时间', chooseList)" />

        <el-table-column label="点呼" prop="exportCntSingle" width="80" v-if="handleShow('点呼导出次数', chooseList)" />

        <el-table-column label="群呼" prop="exportCntBatch" width="80" v-if="handleShow('群呼导出次数', chooseList)" />

        <el-table-column label="AI" prop="exportCntAi" width="80" v-if="handleShow('AI导出次数', chooseList)" />
        <el-table-column label="企业类型" prop="capTypeName" width="160" v-if="handleShow('企业类型', chooseList)" />
        <el-table-column label="纳税开票同步状态" prop="nsStatus" width="160" v-if="handleShow('纳税开票同步状态', chooseList)">
          <template #default="scope">
            <el-tag v-if="scope.row.nsStatus == 1" type="success">
              已同步
            </el-tag>
            <el-tag v-if="scope.row.nsStatus == 2" type="warning">
              已同步但无数据
            </el-tag>
            <el-tag v-if="scope.row.nsStatus == -1" type="danger">
              未同步
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="最低纳税额度(万元)" prop="nsInfo" width="160" v-if="handleShow('最低纳税额度(万元)', chooseList)" />
        <el-table-column label="最低开票额度(万元)" prop="kpInfo" width="160" v-if="handleShow('最低开票额度(万元)', chooseList)" />
        <el-table-column label="风险总计情况" prop="allHis" width="160" v-if="handleShow('风险总计情况', chooseList)">
          <template #default="scope">
            <el-button type="primary" text @click="viewHisDetail(scope.row)">
              {{
                scope.row.allHis == -1
                  ? '未知'
                  : scope.row.allHis == 0
                    ? '否'
                    : scope.row.allHis == 1
                      ? '是'
                      : ''
              }}
            </el-button>
          </template>
        </el-table-column>
        <el-table-column label="企业标签" prop="haveTag" width="160" v-if="handleShow('企业标签', chooseList)">
          <template #default="scope">
            <el-button type="primary" text @click="viewTagDetail(scope.row)">
              {{
                scope.row.haveTag == -1
                  ? '未知'
                  : scope.row.haveTag == 0
                    ? '否'
                    : scope.row.haveTag == 1
                      ? '是'
                      : ''
              }}
            </el-button>
          </template>
        </el-table-column>
        <!-- <el-table-column
          label="是否有自身风险"
          prop="ownHis"
          width="160"
          v-if="handleShow('是否有自身风险', chooseList)"
        >
          <template #default="scope">
            {{
              scope.row.ownHis == -1
                ? '未知'
                : scope.row.ownHis == 0
                ? '否'
                : scope.row.ownHis == 1
                ? '是'
                : ''
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="是否有关联风险"
          prop="corHis"
          width="160"
          v-if="handleShow('是否有关联风险', chooseList)"
        >
          <template #default="scope">
            {{
              scope.row.corHis == -1
                ? '未知'
                : scope.row.corHis == 0
                ? '否'
                : scope.row.corHis == 1
                ? '是'
                : ''
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="是否有其他风险"
          prop="otherHis"
          width="160"
          v-if="handleShow('是否有其他风险', chooseList)"
        >
          <template #default="scope">
            {{
              scope.row.otherHis == -1
                ? '未知'
                : scope.row.otherHis == 0
                ? '否'
                : scope.row.otherHis == 1
                ? '是'
                : ''
            }}
          </template>
        </el-table-column> -->
        <el-table-column label="过滤原因" prop="filterateRes" v-if="
          queryParams.filterateCompany == 0 ||
          handleShow('过滤原因', chooseList)
        ">
          <template #default="scope">
            {{ filterateResCal(scope.row) }}
          </template>
        </el-table-column>
        <!-- <el-table-column label="同步推送" prop="">
                    <template #default="scope">
                        <span></span>
                    </template>
                </el-table-column> -->

        <el-table-column label="操作" prop="option" fixed="right" width="100">
          <template #default="scope">
            <span>
              <!-- <el-button
                        link
                        type="primary"
                        >编辑</el-button> -->
              <el-button link type="primary" @click="handleDelete('only', scope.row)">
                删除
              </el-button>
            </span>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-model:limit="queryParams.pageSize" v-model:page="queryParams.pageNum" :total="queryParams.total"
        @pagination="handleQuery" />
    </div>

    <!-- 同步/导出：弹框 -->
    <el-dialog :title="state.sync ? '同步数据' : '导出数据'" :close-on-click-modal="false" :close-on-press-escape="false"
      width="800px" @close="handleQuery" v-model="state.visible">
      <exportFile v-if="state.visible"></exportFile>
      <slot></slot>
    </el-dialog>

    <!-- 数据汇总：弹框 -->
    <el-drawer size="800px" title="数据汇总" v-model="summryVisible">
      <summaryData v-if="summryVisible" @province-click="handleSummaryProvinceClick"></summaryData>
    </el-drawer>

    <!-- 列展示 -->
    <el-dialog v-model="dialogVisible" title="展示列" width="600px" :before-close="handleColumnsClose">
      <div class="chooseTag">
        <div class="chooseTagItem" v-for="(item, index) in chooseList" :key="index">
          <el-checkbox v-model="item.checked" :label="item.name" @change="handleCheck(item.name, item.checked)" />
        </div>
      </div>
    </el-dialog>

    <!-- 更多查询条件 -->
    <el-drawer v-model="drawer" title="筛选" size="405px">
      <el-form :model="queryParams" ref="queryRefMore" :inline="true" label-width="150px">
        <el-form-item label="校对法人" prop="checkLegal">
          <el-input size="small" class="wh" v-model.trim="queryParams.checkLegal" placeholder="请输入校对法人" />
        </el-form-item>

        <el-form-item label="导入法人" prop="legalPerson">
          <el-input size="small" class="wh" v-model.trim="queryParams.legalPerson" placeholder="请输入导入法人" />
        </el-form-item>

        <el-form-item label="注册资金">
          <el-row :gutter="24">
            <el-col :span="11">
              <el-form-item prop="regCapMin">
                <el-input size="small" v-model="queryParams.regCapMin" placeholder="请输入">
                  <template #append>万</template>
                </el-input>
              </el-form-item>
            </el-col>
            <span style="margin-left: 10px">~</span>
            <el-col :span="11">
              <el-form-item prop="regCapMax">
                <el-input size="small" v-model="queryParams.regCapMax" placeholder="请输入">
                  <template #append>万</template>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form-item>

        <el-form-item label="实缴资金">
          <el-row :gutter="24">
            <el-col :span="11">
              <el-form-item prop="paidCapMin">
                <el-input size="small" controls-position="right" v-model="queryParams.paidCapMin" placeholder="请输入">
                  <template #append>万</template>
                </el-input>
              </el-form-item>
            </el-col>
            <span style="margin-left: 10px">~</span>
            <el-col :span="11">
              <el-form-item prop="paidCapMax">
                <el-input size="small" controls-position="right" v-model="queryParams.paidCapMax" placeholder="请输入">
                  <template #append>万</template>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form-item>

        <el-form-item label="一级行业" prop="industryphy">
          <el-select v-model="queryParams.industryphy" multiple class="wh" placeholder="请选择一级行业" size="small">
            <el-option v-for="item in topIndustryPhy" :key="item.id" :label="item.name" :value="item.name" />
          </el-select>
        </el-form-item>

        <el-form-item label="二级行业" prop="industryphy1">
          <el-input size="small" class="wh" v-model.trim="queryParams.industryphy1" placeholder="请输入二级行业" />
        </el-form-item>

        <el-form-item label="三级行业" prop="industryphy2">
          <el-input size="small" class="wh" v-model.trim="queryParams.industryphy2" placeholder="请输入三级行业" />
        </el-form-item>

        <el-form-item label="四级行业" prop="enttypeName">
          <el-input size="small" class="wh" v-model.trim="queryParams.enttypeName" placeholder="请输入四级行业" />
        </el-form-item>

        <el-form-item label="信用代码" prop="creditCode">
          <el-input size="small" class="wh" v-model.trim="queryParams.creditCode" placeholder="请输入信用代码" />
        </el-form-item>
        <el-form-item label="历史有借款/合同纠纷" prop="isJdjfHis">
          <el-select v-model="queryParams.isJdjfHis" size="small" clearable class="wh">
            <el-option :value="0" label="否"></el-option>
            <el-option :value="-1" label="未知"></el-option>
            <el-option :value="1" label="是"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="历史有异常经营" prop="isJyycHis">
          <el-select v-model="queryParams.isJyycHis" size="small" clearable class="wh">
            <el-option :value="0" label="否"></el-option>
            <el-option :value="-1" label="未知"></el-option>
            <el-option :value="1" label="是"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="近3年内有借款/合同纠纷" prop="isJdjfIn3Year">
          <el-select v-model="queryParams.isJdjfIn3Year" size="small" clearable class="wh">
            <el-option :value="0" label="否"></el-option>
            <el-option :value="-1" label="未知"></el-option>
            <el-option :value="1" label="是"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="近2年内有异常经营" prop="isJyycIn2Year">
          <el-select v-model="queryParams.isJyycIn2Year" size="small" clearable class="wh">
            <el-option :value="0" label="否"></el-option>
            <el-option :value="-1" label="未知"></el-option>
            <el-option :value="1" label="是"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="税务异常" prop="isSwyc">
          <el-select v-model="queryParams.isSwyc" size="small" clearable class="wh">
            <el-option :value="0" label="否"></el-option>
            <el-option :value="-1" label="未知"></el-option>
            <el-option :value="1" label="是"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="注销相关" prop="isZxxg">
          <el-select v-model="queryParams.isZxxg" size="small" clearable class="wh">
            <el-option :value="0" label="否"></el-option>
            <el-option :value="-1" label="未知"></el-option>
            <el-option :value="1" label="是"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="自身风险-被执行人" prop="isBzxrZs">
          <el-select v-model="queryParams.isBzxrZs" size="small" clearable class="wh">
            <el-option :value="0" label="否"></el-option>
            <el-option :value="-1" label="未知"></el-option>
            <el-option :value="1" label="是"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="自身风险-限制高消费" prop="isXzxfZs">
          <el-select v-model="queryParams.isXzxfZs" size="small" clearable class="wh">
            <el-option :value="0" label="否"></el-option>
            <el-option :value="-1" label="未知"></el-option>
            <el-option :value="1" label="是"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="自身风险-严重违法" prop="isYzwfZs">
          <el-select v-model="queryParams.isYzwfZs" size="small" clearable class="wh">
            <el-option :value="0" label="否"></el-option>
            <el-option :value="-1" label="未知"></el-option>
            <el-option :value="1" label="是"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="自身风险-终本案件" prop="isZhongbenZs">
          <el-select v-model="queryParams.isZhongbenZs" size="small" clearable class="wh">
            <el-option :value="0" label="否"></el-option>
            <el-option :value="-1" label="未知"></el-option>
            <el-option :value="1" label="是"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关联风险-被执行人" prop="isBzxrGl">
          <el-select v-model="queryParams.isBzxrGl" size="small" clearable class="wh">
            <el-option :value="0" label="否"></el-option>
            <el-option :value="-1" label="未知"></el-option>
            <el-option :value="1" label="是"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关联风险-限制高消费" prop="isXzxfGl">
          <el-select v-model="queryParams.isXzxfGl" size="small" clearable class="wh">
            <el-option :value="0" label="否"></el-option>
            <el-option :value="-1" label="未知"></el-option>
            <el-option :value="1" label="是"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="关联风险-严重违法" prop="isYzwfGl">
          <el-select v-model="queryParams.isYzwfGl" size="small" clearable class="wh">
            <el-option :value="0" label="否"></el-option>
            <el-option :value="-1" label="未知"></el-option>
            <el-option :value="1" label="是"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关联风险-终本案件" prop="isZhongbenGl">
          <el-select v-model="queryParams.isZhongbenGl" size="small" clearable class="wh">
            <el-option :value="0" label="否"></el-option>
            <el-option :value="-1" label="未知"></el-option>
            <el-option :value="1" label="是"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <div style="flex: auto">
          <el-button size="small" @click="saveModelDialogChange(true)">
            设置为模板
          </el-button>
          <el-button size="small" @click="handleReset">重置</el-button>
          <el-button size="small" type="primary" @click="handleSearch">
            查询
          </el-button>
        </div>
      </template>
    </el-drawer>

    <!-- 更更多查询条件 -->
    <el-drawer v-model="tagDrawer" title="标签筛选" size="405px">
      <el-form :model="queryParams" ref="queryRefMore" :inline="true" label-width="120px">
        <el-form-item label="标签条件" prop="tagCondition">
          <el-select v-model="queryParams.tagCondition" clearable class="wh" placeholder="请选择标签条件" size="small">
            <el-option label="满足其一" :value="2" />
            <el-option label="全部满足" :value="1" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否雏鹰企业" prop="isCy">
          <el-select clearable v-model="queryParams.isCy" class="wh" placeholder="请选择是否雏鹰企业" size="small">
            <el-option v-for="item in whetherOrNotOptions" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否独角兽企业" prop="isDjs">
          <el-select clearable v-model="queryParams.isDjs" class="wh" placeholder="请选择是否独角兽企业" size="small">
            <el-option v-for="item in whetherOrNotOptions" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否瞪羚企业" prop="isDl">
          <el-select clearable v-model="queryParams.isDl" class="wh" placeholder="请选择是否瞪羚企业" size="small">
            <el-option v-for="item in whetherOrNotOptions" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否规模限额" prop="isGsxz">
          <el-select clearable v-model="queryParams.isGsxz" class="wh" placeholder="请选择是否规模限额" size="small">
            <el-option v-for="item in whetherOrNotOptions" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否高新企业" prop="isGx">
          <el-select clearable v-model="queryParams.isGx" class="wh" placeholder="请选择是否高新企业" size="small">
            <el-option v-for="item in whetherOrNotOptions" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否专精特新小巨人" prop="isXjr">
          <el-select clearable v-model="queryParams.isXjr" class="wh" placeholder="请选择是否专精特新小巨人" size="small">
            <el-option v-for="item in whetherOrNotOptions" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否小微企业" prop="isXwqy">
          <el-select clearable v-model="queryParams.isXwqy" class="wh" placeholder="请选择是否小微企业" size="small">
            <el-option v-for="item in whetherOrNotOptions" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否科技型中小企业" prop="isKjzx">
          <el-select clearable v-model="queryParams.isKjzx" class="wh" placeholder="请选择是否科技型中小企业" size="small">
            <el-option v-for="item in whetherOrNotOptions" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否专精特新企业" prop="isZjtx">
          <el-select clearable v-model="queryParams.isZjtx" class="wh" placeholder="请选择是否专精特新企业" size="small">
            <el-option v-for="item in whetherOrNotOptions" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否500强企业" prop="is500">
          <el-select clearable v-model="queryParams.is500" class="wh" placeholder="请选择是否500强企业" size="small">
            <el-option v-for="item in whetherOrNotOptions" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <div style="flex: auto">
          <el-button size="small" @click="saveModelDialogChange(true)">
            设置为模板
          </el-button>
          <el-button size="small" @click="handleReset">重置</el-button>
          <el-button size="small" type="primary" @click="handleSearch">
            查询
          </el-button>
        </div>
      </template>
    </el-drawer>

    <!-- 保存为模板 -->
    <el-dialog v-model="saveModelDialogVisible" title="保存模板" width="30%" align-center>
      <el-form :model="modelForm" label-width="120px" ref="modelFormRef">
        <el-form-item label="模板名称" prop="name" style="margin-bottom: 20px">
          <el-input v-model="modelForm.name" />
        </el-form-item>
        <el-form-item label="模板简介" prop="introduce">
          <el-input v-model="modelForm.introduce" />
        </el-form-item>
      </el-form>

      <template #footer>
        <span class="dialog-footer">
          <el-button @click="saveModelDialogChange(false)">取消</el-button>
          <el-button type="primary" @click="handleCreateSearchModel()">
            保存
          </el-button>
        </span>
      </template>
    </el-dialog>

    <el-dialog v-model="hisDetailDialog" title="风险详情" width="500" align-center>
      <div class="his-wrap">
        <div>
          <span style="font-weight: bold">历史有借款/合同纠纷：</span>
          <el-tag v-if="currentHisDetail.isJdjfHis == 0" type="success">
            否
          </el-tag>
          <el-tag v-if="currentHisDetail.isJdjfHis == 1" type="danger">
            是
          </el-tag>
          <el-tag v-if="currentHisDetail.isJdjfHis == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">历史有异常经营：</span>

          <el-tag v-if="currentHisDetail.isJyycHis == 0" type="success">
            否
          </el-tag>
          <el-tag v-if="currentHisDetail.isJyycHis == 1" type="danger">
            是
          </el-tag>
          <el-tag v-if="currentHisDetail.isJyycHis == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">近3年内有借款/合同纠纷：</span>
          <el-tag v-if="currentHisDetail.isJdjfIn3Year == 0" type="success">
            否
          </el-tag>
          <el-tag v-if="currentHisDetail.isJdjfIn3Year == 1" type="danger">
            是
          </el-tag>
          <el-tag v-if="currentHisDetail.isJdjfIn3Year == -1" type="warning">
            未知
          </el-tag>
        </div>

        <div>
          <span style="font-weight: bold">近2年内有异常经营：</span>

          <el-tag v-if="currentHisDetail.isJyycIn2Year == 0" type="success">
            否
          </el-tag>
          <el-tag v-if="currentHisDetail.isJyycIn2Year == 1" type="danger">
            是
          </el-tag>
          <el-tag v-if="currentHisDetail.isJyycIn2Year == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">税务异常：</span>
          <el-tag v-if="currentHisDetail.isSwyc == 0" type="success">否</el-tag>
          <el-tag v-if="currentHisDetail.isSwyc == 1" type="danger">是</el-tag>
          <el-tag v-if="currentHisDetail.isSwyc == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">注销相关：</span>
          <el-tag v-if="currentHisDetail.isZxxg == 0" type="success">否</el-tag>
          <el-tag v-if="currentHisDetail.isZxxg == 1" type="danger">是</el-tag>
          <el-tag v-if="currentHisDetail.isZxxg == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">自身风险-被执行人：</span>
          <el-tag v-if="currentHisDetail.isBzxrZs == 0" type="success">
            否
          </el-tag>
          <el-tag v-if="currentHisDetail.isBzxrZs == 1" type="danger">
            是
          </el-tag>
          <el-tag v-if="currentHisDetail.isBzxrZs == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">自身风险-限制高消费：</span>
          <el-tag v-if="currentHisDetail.isXzxfZs == 0" type="success">
            否
          </el-tag>
          <el-tag v-if="currentHisDetail.isXzxfZs == 1" type="danger">
            是
          </el-tag>
          <el-tag v-if="currentHisDetail.isXzxfZs == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">自身风险-严重违法：</span>
          <el-tag v-if="currentHisDetail.isYzwfZs == 0" type="success">
            否
          </el-tag>
          <el-tag v-if="currentHisDetail.isYzwfZs == 1" type="danger">
            是
          </el-tag>
          <el-tag v-if="currentHisDetail.isYzwfZs == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">自身风险-终本案件：</span>
          <el-tag v-if="currentHisDetail.isZhongbenZs == 0" type="success">
            否
          </el-tag>
          <el-tag v-if="currentHisDetail.isZhongbenZs == 1" type="danger">
            是
          </el-tag>
          <el-tag v-if="currentHisDetail.isZhongbenZs == -1" type="warning">
            未知
          </el-tag>
        </div>

        <div>
          <span style="font-weight: bold">关联风险-被执行人：</span>
          <el-tag v-if="currentHisDetail.isBzxrGl == 0" type="success">
            否
          </el-tag>
          <el-tag v-if="currentHisDetail.isBzxrGl == 1" type="danger">
            是
          </el-tag>
          <el-tag v-if="currentHisDetail.isBzxrGl == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">关联风险-限制高消费：</span>
          <el-tag v-if="currentHisDetail.isXzxfGl == 0" type="success">
            否
          </el-tag>
          <el-tag v-if="currentHisDetail.isXzxfGl == 1" type="danger">
            是
          </el-tag>
          <el-tag v-if="currentHisDetail.isXzxfGl == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">关联风险-严重违法：</span>
          <el-tag v-if="currentHisDetail.isYzwfGl == 0" type="success">
            否
          </el-tag>
          <el-tag v-if="currentHisDetail.isYzwfGl == 1" type="danger">
            是
          </el-tag>
          <el-tag v-if="currentHisDetail.isYzwfGl == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">关联风险-终本案件：</span>
          <el-tag v-if="currentHisDetail.isZhongbenGl == 0" type="success">
            否
          </el-tag>
          <el-tag v-if="currentHisDetail.isZhongbenGl == 1" type="danger">
            是
          </el-tag>
          <el-tag v-if="currentHisDetail.isZhongbenGl == -1" type="warning">
            未知
          </el-tag>
        </div>
      </div>
    </el-dialog>

    <el-dialog v-model="tagDetailDialog" title="企业标签详情" width="500" align-center>
      <div class="his-wrap">
        <div>
          <span style="font-weight: bold">是否雏鹰企业：</span>
          <el-tag v-if="currentTagDetail.isCy == 0" type="success">否</el-tag>
          <el-tag v-if="currentTagDetail.isCy == 1" type="danger">是</el-tag>
          <el-tag v-if="currentTagDetail.isCy == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">是否独角兽企业：</span>

          <el-tag v-if="currentTagDetail.isDjs == 0" type="success">否</el-tag>
          <el-tag v-if="currentTagDetail.isDjs == 1" type="danger">是</el-tag>
          <el-tag v-if="currentTagDetail.isDjs == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">是否瞪羚企业：</span>
          <el-tag v-if="currentTagDetail.isDl == 0" type="success">否</el-tag>
          <el-tag v-if="currentTagDetail.isDl == 1" type="danger">是</el-tag>
          <el-tag v-if="currentTagDetail.isDl == -1" type="warning">
            未知
          </el-tag>
        </div>

        <div>
          <span style="font-weight: bold">是否规模以上/限额以上企业：</span>

          <el-tag v-if="currentTagDetail.isGsxz == 0" type="success">否</el-tag>
          <el-tag v-if="currentTagDetail.isGsxz == 1" type="danger">是</el-tag>
          <el-tag v-if="currentTagDetail.isGsxz == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">是否高新企业：</span>
          <el-tag v-if="currentTagDetail.isGx == 0" type="success">否</el-tag>
          <el-tag v-if="currentTagDetail.isGx == 1" type="danger">是</el-tag>
          <el-tag v-if="currentTagDetail.isGx == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">是否专精特新小巨人：</span>
          <el-tag v-if="currentTagDetail.isXjr == 0" type="success">否</el-tag>
          <el-tag v-if="currentTagDetail.isXjr == 1" type="danger">是</el-tag>
          <el-tag v-if="currentTagDetail.isXjr == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">是否小微企业：</span>
          <el-tag v-if="currentTagDetail.isXwqy == 0" type="success">否</el-tag>
          <el-tag v-if="currentTagDetail.isXwqy == 1" type="danger">是</el-tag>
          <el-tag v-if="currentTagDetail.isXwqy == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">是否科技型中小企业：</span>
          <el-tag v-if="currentTagDetail.isKjzx == 0" type="success">否</el-tag>
          <el-tag v-if="currentTagDetail.isKjzx == 1" type="danger">是</el-tag>
          <el-tag v-if="currentTagDetail.isKjzx == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">是否专精特新企业：</span>
          <el-tag v-if="currentTagDetail.isZjtx == 0" type="success">否</el-tag>
          <el-tag v-if="currentTagDetail.isZjtx == 1" type="danger">是</el-tag>
          <el-tag v-if="currentTagDetail.isZjtx == -1" type="warning">
            未知
          </el-tag>
        </div>
        <div>
          <span style="font-weight: bold">是否500强企业：</span>
          <el-tag v-if="currentTagDetail.is500 == 0" type="success">否</el-tag>
          <el-tag v-if="currentTagDetail.is500 == 1" type="danger">是</el-tag>
          <el-tag v-if="currentTagDetail.is500 == -1" type="warning">
            未知
          </el-tag>
        </div>
      </div>
    </el-dialog>
  </div>
  <div v-else class="tac fs28 index-content">欢迎来到{{ VITE_APP_TITLE }}</div>
</template>

<script setup name="FileIndex">
const VITE_APP_TITLE = ref(import.meta.env.VITE_APP_TITLE)
import {
  batchDeleteBySelect,
  deleteFileModel,
  getBatchName,
  getFileModelList,
  getJobStatus,
  getProvincStatistics,
  getTopIndustryPhy,
  postFileList,
  postFileListDelete,
  postFileModelCreate,
  getCapTypeList,
} from '@/api/uploadFile.js'
import InvertSelection from '@/components/InvertSelection'
import { dayjs, ElMessage, ElMessageBox } from 'element-plus'
import { getCurrentInstance, reactive, ref } from 'vue'
import exportFile from './../components/exportFile.vue'
import summaryData from './../components/summaryData.vue'
import useConfig from './hooks/useConfig'
import useUserStore from '@/store/modules/user'
const { roles } = useUserStore()
const {
  postNameOption,
  consistenceOption,
  entstatusNameOption,
  checkMobileOption,
  fileChooseList,
  riskLevelList,
  yearTypes,
  handleShow,
} = useConfig()

const { proxy } = getCurrentInstance()
const provinces = proxy.getProvinces().filter((item) => item.ProID !== -1)

const hasAdmin = computed(() => {
  return roles.some((element) =>
    ['ITServer', 'admin', 'manager', 'admin2'].includes(element)
  )
})

const loading = ref(false)
const tableList = ref([])
const optionList = ref([])
const capTypeList = ref([])
// 查询周期
const dateRange = ref([])
// 勾选框：table 列是否展示
const chooseList = ref(fileChooseList)

// 请求参数
const data = reactive({
  queryParams: {
    // 分页
    pageNum: 1,
    pageSize: 10,
    total: 0,
    // 查询条件
    createTimeStart: '',
    createTimeEnd: '',
    limitCnt: 100000, // 数据限制
    batchNameList: [], // 批次
    // 筛选：input
    exportCntSingleMin: '', // 点呼导出次数
    exportCntSingleMax: '',
    exportCntBatchMin: '', // 群呼导出次数
    exportCntBatchMax: '',
    exportCntAiMin: '', // AI导出次数
    exportCntAiMax: '',
    capTypeNameList: [], //企业类型
    filterateCompany: '1',
    companyName: '', // 企业名称
    phoneNum: '', // 手机号
    checkLegal: '', // 校对法人
    legalPerson: '', // 导入法人
    regCapMin: '', // 注册资金
    regCapMax: '',
    paidCapMin: '', // 实缴资金
    paidCapMax: '',
    yearMin: '', // 年限
    yearMax: '',
    yearType: null,
    industryphy: [], // 一级行业
    industryphy1: '', // 二级行业
    industryphy2: '', // 三级行业
    enttypeName: '', // 四级行业
    creditCode: '', // 信用代码
    // 筛选：select
    provinceList: [], // 省
    overturn: false,
    riskLevel: '', // 风险等级
    consistence: null, // 一致性
    checkMobile: null, // 要素一致性
    postNameList: [], // 类型
    entstatusName: null, // 在营状态
    nsStatus: '',
    nsInfo: null,
    kpInfo: null,
    allHis: null,
    ownHis: null,
    corHis: null,
    otherHis: null,
    isJdjfHis: null,
    isJdjfIn3Year: null,
    isJyycHis: null,
    isJyycIn2Year: null,
    isSwyc: null,
    isBzxrZs: null,
    isXzxfZs: null,
    isYzwfZs: null,
    isZhongbenZs: null,
    isBzxrGl: null,
    isXzxfGl: null,
    isYzwfGl: null,
    isZhongbenGl: null,
    isZxxg: null,

    tagCondition: null, //标签条件为：‘满足其一’2，全部满足：1
    haveTag: null, //是否有标签：1是0否-1未知
    isCy: null, //是否雏鹰企业：1是0否-1未知
    isDjs: null, //是否独角兽企业：1是0否-1未知
    isDl: null, //是否瞪羚企业：1是0否-1未知
    isGsxz: null, //是否规模以上/限额以上企业：1是0否-1未知
    isGx: null, //是否高新企业：1是0否-1未知
    isXjr: null, //是否专精特新小巨人：1是0否-1未知
    isXwqy: null, //是否小微企业：1是0否-1未知
    isKjzx: null, //是否科技型中小企业：1是0否-1未知
    isZjtx: null, //是否专精特新企业：1是0否-1未知
    is500: null, //是否500强企业：1是0否-1未知
  },
  modelForm: {
    name: '',
    introduce: '',
  },
})

const whetherOrNotOptions = [
  {
    value: -1,
    label: '未知',
  },
  {
    value: 0,
    label: '否',
  },
  {
    value: 1,
    label: '是',
  },
]
const { queryParams, modelForm } = toRefs(data)

const filterateResCal = (item) => {
  return item?.filterateRes?.join(',')
}
// 更多查询条件
const drawer = ref(false)
const handleChooseSearch = () => {
  drawer.value = true
}

const tagDrawer = ref(false)
const handleTagSearch = () => {
  tagDrawer.value = true
}

const handleReset = () => {
  clearChoose()
  handleQuery()
}
const handleSearch = () => {
  handleQuery()
  drawer.value = false
  tagDrawer.value = false
}

// 清除筛选
const clearChoose = () => {
  queryParams.value.checkLegal = ''
  queryParams.value.legalPerson = ''
  queryParams.value.regCapMin = null
  queryParams.value.regCapMax = null
  queryParams.value.paidCapMin = null
  queryParams.value.paidCapMax = null
  queryParams.value.industryphy = []
  queryParams.value.industryphy1 = ''
  queryParams.value.industryphy2 = ''
  queryParams.value.enttypeName = ''
  queryParams.value.creditCode = ''
  queryParams.value.overturn = false
  queryParams.value.yearType = 1
  queryParams.value.isJdjfHis = null
  queryParams.value.isJdjfIn3Year = null
  queryParams.value.isJyycHis = null
  queryParams.value.isJyycIn2Year = null
  queryParams.value.isSwyc = null
  queryParams.value.isBzxrZs = null
  queryParams.value.isXzxfZs = null
  queryParams.value.isYzwfZs = null
  queryParams.value.isZhongbenZs = null
  queryParams.value.isBzxrGl = null
  queryParams.value.isXzxfGl = null
  queryParams.value.isYzwfGl = null
  queryParams.value.isZhongbenGl = null
  queryParams.value.isZxxg = null
  queryParams.value.tagCondition = null
  queryParams.value.haveTag = null
  queryParams.value.isCy = null
  queryParams.value.isDjs = null
  queryParams.value.isDl = null
  queryParams.value.isGsxz = null
  queryParams.value.isGx = null
  queryParams.value.isXjr = null
  queryParams.value.isXwqy = null
  queryParams.value.isKjzx = null
  queryParams.value.isZjtx = null
  queryParams.value.is500 = null
}

// 重置
const resetQuery = () => {
  proxy.$refs['multipleTableRef'].clearSelection()
  dateRange.value = []
  chooseList.value = fileChooseList
  queryParams.value.createTimeStart = ''
  queryParams.value.createTimeEnd = ''

  clearChoose()

  proxy.$refs['queryRef'].resetFields()
  handleQuery()
}

// 周期
const handleDateValue = (val) => {
  queryParams.value.createTimeStart = val?.[0] ?? ''
  queryParams.value.createTimeEnd = val?.[1] ?? ''
}

/**
 * @description: 批量操作
 * @param {*} row
 * @return {*}
 */
const multipleTableRef = ref()
const multipleSelection = ref([]) // 多选的数据
const handleSelectionChange = (val) => {
  multipleSelection.value = val
}
// 删除/批量删除
const handleDelete = (type, row) => {
  // 1、多选时：未选数据提示
  if (type === 'all' && multipleSelection.value?.length === 0) {
    ElMessage({
      message: '请选择要删除的数据',
      type: 'warning',
    })
    return
  }

  ElMessageBox.confirm(`确定删除选择的数据么？`, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
  })
    .then(async () => {
      if (type === 'all') {
        const res = await getJobStatus()
        if (res.msg === 'true') {
          ElMessage.error('当前有正在进行中的任务，请稍后再试')
          return
        }
      }

      let params = []
      if (type === 'only') {
        // 单个删除
        params = [row.id]
      } else {
        // 多个删除
        multipleSelection.value.map((item) => {
          params.push(item.id)
        })
      }

      postFileListDelete({
        ids: params,
      }).then((res) => {
        if (res?.code === 200) {
          ElMessage({
            message: '删除成功',
            type: 'success',
          })
          proxy.$refs['multipleTableRef'].clearSelection()
          handleQuery()
        } else {
          ElMessage({
            message: '删除失败',
            type: 'error',
          })
        }
      })
    })
    .catch(() => { })
}

/**
 *  按搜索条件删除
 */
function handleDeleteByParams() {
  ElMessageBox.confirm(`确定删除所有符合搜索条件的数据吗？`, '提示', {
    type: 'danger',
  }).then(() => {
    batchDeleteBySelect({
      ...queryParams.value,
      nsInfo: JSON.stringify(queryParams.value.nsInfo),
      kpInfo: JSON.stringify(queryParams.value.kpInfo),
      overturn: queryParams.value.overturn ? 1 : 0,
      yearMin:
        queryParams.value.yearType === 0
          ? undefined
          : queryParams.value.yearType,
      yearMax: queryParams.value.yearType === 0 ? 1 : undefined,
    }).then((res) => {
      if (res.code === 200) {
        ElMessage.success('删除成功')
        proxy.$refs['multipleTableRef'].clearSelection()
        handleQuery()
      } else {
        ElMessage.error('删除失败')
      }
    })
  })
}

// 获取：批次：下拉列表
const initOption = () => {
  getBatchName().then((res) => {
    optionList.value = res?.data || []
  })
}

// 获取：企业类型：下拉列表
const initCapTypeOption = () => {
  getCapTypeList().then((res) => {
    capTypeList.value = res?.data.map((o, i) => {
      return { id: i, name: o }
    })
    // [
    //   "其他",
    //   "个体",
    //   "普通合伙",
    //   "集体所有制",
    //   "国有企业",
    //   "港、澳、台",
    //   "有限合伙",
    //   "私营企业",
    //   "联营企业",
    //   "外商投资企业",
    //   "个体独资企业",
    //   "有限责任公司",
    //   "股份有限公司",
    // ].map((o, i) => {
    //   return { id: i, name: o };
    // });
  })
}

// 获取：列表
const handleQuery = () => {
  // 把查询条件存入缓存
  localStorage.setItem('searchList', JSON.stringify(queryParams.value))
  loading.value = true
  // 获取列表
  postFileList({
    ...queryParams.value,
    nsInfo: JSON.stringify(queryParams.value.nsInfo),
    kpInfo: JSON.stringify(queryParams.value.kpInfo),
    overturn: queryParams.value.overturn ? 1 : 0,
    yearMin:
      queryParams.value.yearType === 0 ? undefined : queryParams.value.yearType,
    yearMax: queryParams.value.yearType === 0 ? 1 : undefined,
  })
    .then((res) => {
      tableList.value = res.rows
      if (res.total < queryParams.value.limitCnt) {
        queryParams.value.total = res.total
      } else {
        queryParams.value.total = queryParams.value.limitCnt
      }
    })
    .finally(() => {
      loading.value = false
    })
}

// 列展示
const dialogVisible = ref(false)
const handleColumnsShow = () => {
  dialogVisible.value = true
}
const handleColumnsClose = () => {
  dialogVisible.value = false
}
// 多选框
const handleCheck = (val, status) => {
  chooseList.value = chooseList.value.reduce((list, item) => {
    if (val === item.name) {
      item.checked = status
    }
    list.push(item)
    return list
  }, [])
  localStorage.setItem('chooseBox', JSON.stringify(chooseList.value))
}

onMounted(() => {
  // 1、查询条件：是否有缓存
  const arr = JSON.parse(localStorage.getItem('searchList'))
  if ((arr && Object.keys(arr).length === 0) || arr === null) {
    queryParams.value.postNameList = []
  } else {
    // 正常初始化
    queryParams.value = arr
    dateRange.value = [
      queryParams.value.createTimeStart,
      queryParams.value.createTimeEnd,
    ]
  }
  // 2、table 表头：是否有缓存
  const result = JSON.parse(localStorage.getItem('chooseBox'))
  chooseList.value =
    (result && Object.keys(result).length === 0) || result === null
      ? fileChooseList
      : result
  initOption()
  initCapTypeOption()
  //   handleQuery();//默认进入不加载数据
  getSearchModelList()
  // 获取一级行业类型代码
  getTopIndustryPhy().then((res) => {
    topIndustryPhy.value = res.data
  })
})

/**
 * @description: 原先模块引入
 * @return {*}
 */
// 数据汇总
const summryVisible = ref(false)
const handleDataSummary = () => {
  summryVisible.value = true
}

const state = reactive({
  sync: false,
  limitInfo: {
    number: 0,
    editorableData: [], // table  可编辑的数据的数量
    frozenNumber: 0,
  },
  postNames: [
    { label: 'A', value: 'A' },
    { label: 'B', value: 'B' },
    { label: 'C', value: 'C' },
    { label: 'N', value: 'N' },
  ],
  exportDataCount: [], // 导出数据
  exportDataLoading: false,
  translate(val, key) {
    val[key] = val[key] ? val[key].toString() : null
  },
  modelList: [], // 我的模版数据
  visible: false,
  //   summryVisible: false,
  id: null,
  exportCntArea: {
    exportCntMin: '',
    exportCntMax: '',
  },
  getParams: () => {
    const { pageNum, pageSize, ...params } = queryParams.value
    return {
      ...params,
      nsInfo: JSON.stringify(queryParams.value.nsInfo),
      kpInfo: JSON.stringify(queryParams.value.kpInfo),
      overturn: queryParams.value.overturn ? 1 : 0,
      yearMin:
        queryParams.value.yearType === 0
          ? undefined
          : queryParams.value.yearType,
      yearMax: queryParams.value.yearType === 0 ? 1 : undefined,
    }
  },
  getPagination: () => {
    const { pageNum, pageSize } = queryParams.value
    return { pageNum, pageSize }
  },
})

const handleExport = async (
  data,
  sync = false /** true 同步 ；false 导出 */
) => {
  const res = await getJobStatus()
  if (res.msg === 'true') {
    ElMessage.error('当前有正在进行中的任务，请稍后再试')
    return
  }
  state.sync = sync
  state.exportDataCount = []
  state.limitInfo.frozenNumber = 0
  state.limitInfo.number = 0
  state.visible = true
  state.exportDataLoading = true
  const params = state.getParams()
  state.translate(params, 'postName')
  state.translate(params, 'province')
  state.translate(params, 'batchName')
  params.synced = sync === true ? false : null // 同步时传false 选择非同步的数据 ，导出不传
  console.log('第一步', params)

  getProvincStatistics(params)
    .then((res) => {
      state.exportDataLoading = false
      const par =
        /^浙江|上海|北京|天津|重庆|黑龙江|吉林|辽宁|内蒙古|河北|新疆|甘肃|青海|陕西|宁夏|河南|山东|山西|安徽|湖北|湖南|江苏|四川|贵州|云南|广西|西藏|江西|广东|福建|台湾|海南|香港|澳门$/
      const obj = {}

      state.limitInfo.number = 0
      state.limitInfo.frozenNumber = 0
      state.limitInfo.editorableData = []
      res.data.forEach((_) => {
        if (!_.province) {
          _.province = '未知'
        }
        if (_.province) {
          if (_.count) {
            state.limitInfo.editorableData.push(_)
          }
          state.limitInfo.number += _.count * 1
          state.limitInfo.frozenNumber += _.count * 1
          // console.log(_, state.limitInfo.number)
          if (obj[_.province]) {
            Object.assign(obj[_.province], {
              province: _.province,
              [_.postName]: _.count,
              ['count' + _.postName]: _.count,
            })
          } else {
            obj[_.province] = {
              province: _.province,
              [_.postName]: _.count,
              ['count' + _.postName]: _.count,
            }
          }
        }
      })
      state.exportDataCount = Object.values(obj) || []
    })
    .finally((e) => {
      state.exportDataLoading = false
    })
}

// 搜索模板
const modelList = ref([])

const saveModelDialogVisible = ref(false)

const topIndustryPhy = ref([])

function saveModelDialogChange(val) {
  if (!val) {
    proxy.$refs['modelFormRef'].resetFields()
  }
  saveModelDialogVisible.value = val
}

//获取搜索模板列表
const getSearchModelList = () => {
  getFileModelList({
    modelName: '首页',
  }).then((res) => {
    modelList.value = res.data
  })
}

//删除搜索模板
const handleDeleteSearchModel = (id) => {
  deleteFileModel({
    id: id,
  }).then((res) => {
    ElMessage({
      message: '搜索模板删除成功',
      type: 'success',
    })
    getSearchModelList()
  })
}

//创建搜索模板
const handleCreateSearchModel = (form) => {
  postFileModelCreate({
    name: modelForm.value.name,
    introduce: modelForm.value.introduce,
    content: JSON.stringify(queryParams.value),
    modelName: '首页',
  }).then((res) => {
    ElMessage({
      message: '搜索模板新增成功',
      type: 'success',
    })
    saveModelDialogChange(false)
    getSearchModelList()
  })
}

const handleClickSearchModel = (row) => {
  queryParams.value = JSON.parse(row)
  dateRange.value = [
    JSON.parse(row).createTimeStart,
    JSON.parse(row).createTimeEnd,
  ]
}

function handleSummaryProvinceClick(item) {
  summryVisible.value = false
  clearChoose()
  queryParams.value.consistence = null
  queryParams.value.yearType = null
  queryParams.value.entstatusName = null
  queryParams.value.postNameList = []
  queryParams.value.batchNameList = []
  queryParams.value.capTypeNameList = []
  queryParams.value.industryphy = []
  queryParams.value.limitCnt = Math.max(
    item.companyCnt,
    queryParams.value.limitCnt
  )
  queryParams.value.provinceList = [item.province]
  handleQuery()
}

const hisDetailDialog = ref(false)
const currentHisDetail = ref()
const viewHisDetail = (row) => {
  hisDetailDialog.value = true
  currentHisDetail.value = row
}

const tagDetailDialog = ref(false)
const currentTagDetail = ref()
const viewTagDetail = (row) => {
  tagDetailDialog.value = true
  currentTagDetail.value = row
}

provide('state', state)
</script>

<style scoped lang="less">
.searchData {
  position: relative;
  height: calc(100vh - 84px);
  display: flex;
  align-items: flex-start;

  .left {
    padding: 20px;
    width: 225px;
    flex-shrink: 0;
    height: 100%;
    overflow-y: auto;

    h4 {
      margin-top: 0;
    }

    .model-group {
      .model-item:hover .model-close {
        display: block;
      }

      .model-item {
        cursor: pointer;
        background: #f4f7fa;
        border-radius: 10px;
        width: 100%;
        margin-bottom: 12px;
        position: relative;
        padding: 10px 16px;

        h5 {
          margin: 0;
          padding-bottom: 10px;
        }

        .model-close {
          display: none;
          background: #e3e3e3;
          border: none;
          position: absolute;
          right: -10px;
          top: -10px;
        }

        .model-introduce,
        .model-time {
          line-height: 1.5;
          font-size: 12px;
          color: #333;
        }
      }
    }
  }

  .right {
    padding: 20px;
    flex-grow: 1;
    height: 100%;
    overflow-y: auto;
    position: relative;
  }
}

.headRight {
  display: flex;
  justify-content: flex-end;
}

.wh {
  width: 252px;
}

.chooseTag {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 30px;

  .chooseTagItem {
    width: 20%;
    margin-right: 20px;
  }
}

::v-deep(.el-form-item--default .el-form-item__label) {
  font-size: 12px;
  font-weight: 400;
}

::v-deep(.el-drawer__header) {
  margin-bottom: 0;
}

::v-deep(.el-form-item--default .el-form-item__label) {
  display: flex;
  justify-content: flex-start;
}

::v-deep(.el-form--inline .el-form-item) {
  margin-right: 10px;
}

::v-deep(.el-input-group__append, .el-input-group__prepend) {
  padding: 0 10px;
}

::v-deep(.el-form-item--default) {
  margin-bottom: 1px;
}

.index-content {
  transition: all 1s;
  animation: mymove 1s forwards;
}

.index-content:before {
  background: #fff;
  transform: skew(305deg);
  display: inline-block;
  position: relative;
  content: ' ';
  border-radius: 50%;
  width: 20px;
  height: 20px;
  left: -30px;
  box-shadow: -1px -1px 6px 0px #f4f4f5;
  animation: mymoveBefore 1s 0.6s forwards;
}

.his-wrap {
  div {
    line-height: 2;
  }
}

@keyframes mymoveBefore {
  0% {
    opacity: 0;
    transform: translate3d(0px, 0px, 10px) rotateX(45deg);
  }

  // 30% {
  //   opacity: 0.4;
  //   transform: translate3d(60px, 20px, 10px)  rotateX(45deg);
  // }
  // 60% {
  //   opacity: 0.4;
  //   transform: translate3d(120px, 0px, 10px)  rotateX(45deg);
  // }
  90% {
    opacity: 1;
    transform: translate3d(360px, 20px, 10px) rotateX(45deg);
  }

  100% {
    opacity: 0;
    transform: translate3d(660px, 0px, 10px) rotateX(45deg);
  }
}

@keyframes mymove {
  from {
    margin-top: 0;
    opacity: 0.1;
  }

  to {
    margin-top: calc(50vh - 100px);
    opacity: 1;
  }
}
</style>
